package com.dcm.live.controller;

import com.dcm.common.annotation.EnableResponseBodyAdvice;
import com.dcm.live.entity.LiveItemEntity;
import com.dcm.live.service.LiveItemService;
import com.dcm.live.vo.DataAnalysisEntity;
import com.dcm.live.vo.FrontDeskEntity;
import com.dcm.live.vo.LiveRoomdtoEntity;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : [pengrongsheng]
 * @createTime : [2021/3/28]
 */
@Api(tags = "LiveItemController")
@RestController
@EnableResponseBodyAdvice
@RequestMapping("/liveItem")
public class LiveItemController {

    @Autowired
    private LiveItemService liveItemService;

    @ApiOperation("查询所有直播商品")
    @GetMapping("/findAll")
    public List<LiveItemEntity> findAll() {
        return liveItemService.findAll();
    }

    @ApiOperation("根据id查询直播商品")
    @GetMapping("/findItemById")
    public LiveItemEntity findItemById(@RequestParam(value = "id", required = false) Long id) {
        return liveItemService.findItemById(id);
    }

    @ApiOperation("添加")
    @PostMapping("/addLiveItem")
    public void addLiveItem(@RequestBody LiveItemEntity liveItemEntity) {
        liveItemService.addItem(liveItemEntity);
    }

    @ApiOperation("修改")
    @PutMapping("/updateLiveItem")
    public void updateLiveItem(@RequestBody LiveItemEntity liveItemEntity) {
        liveItemService.updateItemStatus(liveItemEntity);
    }

    @ApiOperation("根据关键字或id查询")
    @GetMapping("/findItemByKeyWords")
    public List<LiveItemEntity> findItemByKeyWords(@RequestParam(value = "keyWords", required = false) String keyWords) {
        return liveItemService.findItemByKeyWords(keyWords);
    }

    @ApiOperation("分页")
    @GetMapping("/findPage")
    public PageInfo<LiveItemEntity> findPage(@RequestParam(value = "currentPage", required = false) Integer currentPage,
                                             @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        return liveItemService.findPage(currentPage, pageSize);
    }

    /**
     * dataAnalysisBackground  数据分析后台
     * @param id
     * @return
     */
    @ApiOperation("数据分析 计算下单量、成交量、收货量、退货量")
    @GetMapping("/dataAnalysisBackground")
    public DataAnalysisEntity findData(@RequestParam(value = "id",required = false) Long id){
        return liveItemService. dataAnalysis(id);
    }

    /**
     * dataAnalysisFrontDesk  数据分析前台
     * @param id
     * @return
     */
    @ApiOperation("直播商品点击次数、下单次数")
    @GetMapping("/dataAnalysisFrontDesk")
    public FrontDeskEntity findAnalysis(@RequestParam(value = "id",required = false) Long id){
        return liveItemService.fondest(id);
    }

    @ApiOperation("创建直播间")
    @PostMapping("establishBroadcasting")
    public void establishBroadcasting(@RequestBody LiveRoomdtoEntity liveRoomdtoEntity){
        liveItemService.establishBroadcasting(liveRoomdtoEntity);
    }

}
